#ifndef EDITOR_H
#define EDITOR_H

#include <QtGui/QMainWindow>
#include "ui_editor.h"
#include "library.h"
#include "open_piece_dialog.h"


class Editor : public QMainWindow
{
    Q_OBJECT

public:
    Editor(QWidget *parent = 0);
    Editor(QString, int, QWidget *parent = 0);
    ~Editor();
    
    void clearDrawArea();
    void draw();

protected:
	void paintEvent(QPaintEvent *);
    void mousePressEvent(QMouseEvent *);
    void mouseMoveEvent(QMouseEvent *);
    void mouseReleaseEvent(QMouseEvent *);
    
private slots:
	void changeColor();
	void newPiece();
	void savePiece();
	void saveAsPiece();
	void openPiece();
	void rotatePiece();
	void scalePiece();
	void reflectPiece();
	void translatePiece();
	void addVertex();
	void removeVertex();
	void editVertexes();
    
private:
    Ui::EditorClass ui;
    QImage buffer;
    QString current_library_path;
    Piece current_piece;
    QPointF current_edit_point;
    int current_piece_index, current_edit_point_index;
    bool editing, drawing, closed_piece;
    
    void setupConnections();
    void initialize();
    void resizeBuffer(QImage *, QSize);
    void loadPiece(QString, int);
    void savePiece(QString, bool);
    void drawGuides(QPointF, QPointF);
    void updateListPoints();
};

#endif // EDITOR_H
